<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class CAgent extends CI_Controller {

	public function index()
	{
            $page = array();
            $this->load->helper('html');
            $page['content'] = $this->load->view('CAgent/CAgentIndex', array(), TRUE);
            $this->parser->parse('MasterPage', $page);
        
	}
    
    public function calist()
    {
        $page = array();
        $this->load->helper('html');
        $this->load->model('CAgent_model');
        //print_r($this->CAgent_model->aList());
        $page['content'] = $this->load->view('CAgent/CAgentList', array( 'cagent' => $this->CAgent_model->aList()), TRUE);
        $this->parser->parse('MasterPage', $page);
    }
    /**
     * Добавление контрагента
     */
    public function add()
    {
        $this->load->library('form_validation');

        $this->form_validation->set_rules('cagent', 'Контрагент', 'trim|required|max_lenght[150]');
        $this->form_validation->set_rules('phone', 'Телефон', 'trim|required|max_lenght[20]');


        if ($this->form_validation->run() == FALSE)
        {
            $page['content'] = $this->load->view('CAgent/CAgentAdd', array(), TRUE);
        }
        else
        {
            $this->load->model('CAgent_model');
            $this->CAgent_model->insert(
                    $this->input->post('cagent'),
                    $this->input->post('phone')
            );
            redirect('cagent');
        }        

        $this->load->view('MasterPage', $page);
    }
}

